// pages/inkEventSign1/inkEventSign1.js
import profile from '../../profile.js'

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    lang: app.globalData.language,
    index: profile.inkSign,

    // 上传个人图片
    inkPersonPicImg: [],

    // 在校学生或新锐艺术家
    signChooseNum: 0,
    inkSignChoose: profile.inkSign.inkSignChoose,

  },

  bindSignChooseTap: function (e) {
    let list = this.data.inkSignChoose, id = e.currentTarget.id;
    for (let i=0;i<list.length;i++) {
      if (id == list[i].id) {
        list[i].onthis = true;
      }else{
        list[i].onthis = false;
      }
    }
    this.setData({
      signChooseNum: id,
      inkSignChoose: list
    })
  },

  // 删除个人图片
  deleteUpPerTap: function (e) {
    let list = this.data.inkPersonPicImg, id = e.currentTarget.id;
    console.log(id);
    for (let i=0;i<list.length;i++) {
      if (id == list[i].id) {
        list.splice(i,1);
      }
    }
    this.setData({
      inkPersonPicImg: list
    })
  },

  // 上传个人照片按钮
  bindUploadPerPicTap: function (e) {
    let id = Math.random(), that = this, list = this.data.inkPersonPicImg, object = {};
    if (list.length == 1) return;
    wx.chooseMedia({
      mediaType: 'image',
      sourceType: 'album',
      success(res) {
        //console.log(res.tempFiles[0].tempFilePath);
        object.id = id;
        object.img = res.tempFiles[0].tempFilePath;
        list.push(object)
        that.setData({
          inkPersonPicImg: list
        })
      }
    })
  },

  bindPickerChangeLiv: function (e) {
    let index = profile.inkSign;
    index.inkSignPersonList[3].index = e.detail.value;
    this.setData({
      index,
    })
  },

  bindPickerChangeNat: function (e) {
    let index = profile.inkSign;
    index.inkSignPersonList[2].index = e.detail.value;
    this.setData({
      index,
    })
  },

  bindPickerChangeSex: function (e) {
    let index = profile.inkSign;
    index.inkSignPersonList[1].index = e.detail.value;
    this.setData({
      index,
    })
  },

  // 语言切换事件
  menuTap: function (e) {
    this.setData({
      lang: e.detail.lang
    })
    if (app.globalData.language == 'cn'){
      wx.setNavigationBarTitle({
        title: '大华银行艺术探索'
      })
    }else{
      wx.setNavigationBarTitle({
        title: 'UOB Art Explorer'
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})